<?php

namespace Api\Model;

use Think\Model;

class CreditLogModel extends Model {

    /**
     * @name 新增积分日志
     * @param $name
     * @param $coupon_code
     * @param $type
     * @param $credit
     * @param $rest_credit
     */
    public function addLog($userid, $name, $couponCode, $type, $credit) {
        //用户剩余积分
        $restCredit = D('User')->getUserCredit($userid);
        //新增日志
        $data = array(
            'user_id' => $userid,
            'name' => $name,
            'coupon_code' => $couponCode,
            'type' => $type,
            'credit' => $credit,
            'rest_credit' => $restCredit,
            'create_time' => time()
        );
        $this->add($data);
    }

    function receiveLog($coupon_code, $user_id) {
        $user_info = D('User')->find($user_id);
        $rest_credit = $user_info['credit'];
        
       
        
        $this->addLog($user_id, $font, $coupon_code, 1, $rest_credit);
    }

}
